package com.boco.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.entity.EMR_ZYZD;

public class GetEMR_ZYZDData {
	
	private static final Log log = LogFactory.getLog(GetEMR_ZYZDData.class);
	public static List<EMR_ZYZD> getData()
	{
	    Connection con = null;
	    PreparedStatement pre = null;
	    ResultSet result = null;
	    List<EMR_ZYZD> re = new ArrayList<EMR_ZYZD>();
	    try
	    {
	        Class.forName("oracle.jdbc.driver.OracleDriver");
	        System.out.println("开始尝试连接数据库！");
	        String url = "jdbc:oracle:" + "thin:@172.20.21.12:1521:orcl";
	        String user = "sjzx_hxk";
	        String password = "boco#1234";
	        con = DriverManager.getConnection(url, user, password);
	        System.out.println("连接成功！");
	        
	        String sql = "select "
	        		+"'' as JZJGDM,"
	        		+"a.zyjzlsh as ZYH,"
	        		+"a.zdybid as ZYZD_JBBM,"
	        		+"a.zdmc as ZYZDMC,"
	        		+"a.zdlbbm as ZDLX,"
	        		+"'' as HZZSYH,"
	        		+"a.zdsx as ZDXH,"
	        		+"to_char(a.zdsj,'YYYY-MM-dd HH24:mi:ss') as ZDRQ,"
					+"to_char(a.ywscsj,'YYYY-MM-dd HH24:mi:ss') as BCRQ,"
					+"'' as ZRLSH,"
					+"'' as ORGCODE,"
					+"'' as AREACODE,"
					+"to_char(sysdate,'yyyyMMddHH24miss') as UPLOADTIME,"
					+"'' as  SOURCEID "
					+" from tb_zy_zdmxb a where rownum < 100 ";
	 
	        log.info("查询sql："+sql);
	        pre = con.prepareStatement(sql);
	        result = pre.executeQuery();
	        System.out.println("执行成功");
	        while (result.next()){
//	            System.out.println(result.getInt("YYDAH"));
	        	EMR_ZYZD temp = new EMR_ZYZD();
	        	temp.setJZJGDM(result.getString("JZJGDM"));
	        	temp.setZYH(result.getString("ZYH"));
	        	temp.setZYZD_JBBM(result.getString("ZYZD_JBBM"));
	        	temp.setZYZDMC(result.getString("ZYZDMC"));
	        	temp.setZDLX(result.getString("ZDLX"));
	        	temp.setHZZSYH(result.getString("HZZSYH"));
	        	temp.setZDXH(result.getString("ZDXH"));
	        	temp.setZDRQ(result.getString("ZDRQ"));
	        	temp.setBCRQ(result.getString("BCRQ"));
	        	temp.setZRLSH(result.getString("ZRLSH"));
	        	temp.setORGCODE(result.getString("ORGCODE"));
	        	temp.setAREACODE(result.getString("AREACODE"));
	        	temp.setUPLOADTIME(result.getString("UPLOADTIME"));
	        	temp.setSOURCEID(result.getString("SOURCEID"));
	        	re.add(temp);
	        }
	    }
	    catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    finally
	    {
	        try
	        {
	            if (result != null)
	                result.close();
	            if (pre != null)
	                pre.close();
	            if (con != null)
	                con.close();
	            System.out.println("数据库连接已关闭！");
	        }
	        catch (Exception e)
	        {
	            e.printStackTrace();
	        }
	    }
		return re;
	}
}
